﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract NgheNghiep typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class NgheNghiepDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<NgheNghiepDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.NgheNghiep _currentNgheNghiep = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxNgheNghiepDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxNgheNghiepErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxNgheNghiepBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IDNgheNghiep property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDNgheNghiepDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Ten property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxTenDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Mota property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxMotaDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the MacDinh property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxMacDinhDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the TrangThai property
		/// </summary>
		protected System.Windows.Forms.DataGridViewCheckBoxColumn uxTrangThaiDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.NgheNghiep> _NgheNghiepList;
				
		/// <summary> 
		/// The list of NgheNghiep to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.NgheNghiep> NgheNghiepList
		{
			get {return this._NgheNghiepList;}
			set
			{
				this._NgheNghiepList = value;
				this.uxNgheNghiepBindingSource.DataSource = null;
				this.uxNgheNghiepBindingSource.DataSource = value;
				this.uxNgheNghiepDataGridView.DataSource = null;
				this.uxNgheNghiepDataGridView.DataSource = this.uxNgheNghiepBindingSource;				
				//this.uxNgheNghiepBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxNgheNghiepBindingSource_ListChanged);
				this.uxNgheNghiepBindingSource.CurrentItemChanged += new System.EventHandler(OnNgheNghiepBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnNgheNghiepBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentNgheNghiep = uxNgheNghiepBindingSource.Current as Entities.NgheNghiep;
			
			if (_currentNgheNghiep != null)
			{
				_currentNgheNghiep.Validate();
			}
			//_NgheNghiep.Validate();
			OnCurrentEntityChanged();
		}

		//void uxNgheNghiepBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.NgheNghiep"/> instance.
		/// </summary>
		public Entities.NgheNghiep SelectedNgheNghiep
		{
			get {return this._currentNgheNghiep;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxNgheNghiepDataGridView.VirtualMode;}
			set
			{
				this.uxNgheNghiepDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxNgheNghiepDataGridView.AllowUserToAddRows;}
			set {this.uxNgheNghiepDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxNgheNghiepDataGridView.AllowUserToDeleteRows;}
			set {this.uxNgheNghiepDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxNgheNghiepDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxNgheNghiepDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="NgheNghiepDataGridViewBase"/> class.
		/// </summary>
		public NgheNghiepDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxNgheNghiepDataGridView = new System.Windows.Forms.DataGridView();
			this.uxNgheNghiepBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxNgheNghiepErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDNgheNghiepDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxTenDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxMotaDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxMacDinhDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			this.uxTrangThaiDataGridViewColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxNgheNghiepErrorProvider
			// 
			this.uxNgheNghiepErrorProvider.ContainerControl = this;
			this.uxNgheNghiepErrorProvider.DataSource = this.uxNgheNghiepBindingSource;						
			// 
			// uxNgheNghiepDataGridView
			// 
			this.uxNgheNghiepDataGridView.AutoGenerateColumns = false;
			this.uxNgheNghiepDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxNgheNghiepDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDNgheNghiepDataGridViewColumn,
		this.uxTenDataGridViewColumn,
		this.uxMotaDataGridViewColumn,
		this.uxMacDinhDataGridViewColumn,
		this.uxTrangThaiDataGridViewColumn			});
			this.uxNgheNghiepDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxNgheNghiepDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxNgheNghiepDataGridView.Name = "uxNgheNghiepDataGridView";
			this.uxNgheNghiepDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxNgheNghiepDataGridView.TabIndex = 0;	
			this.uxNgheNghiepDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxNgheNghiepDataGridView.EnableHeadersVisualStyles = false;
			this.uxNgheNghiepDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnNgheNghiepDataGridViewDataError);
			this.uxNgheNghiepDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnNgheNghiepDataGridViewCellValueNeeded);
			this.uxNgheNghiepDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnNgheNghiepDataGridViewCellValuePushed);
			
			//
			// uxIDNgheNghiepDataGridViewColumn
			//
			this.uxIDNgheNghiepDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDNgheNghiepDataGridViewColumn.DataPropertyName = "IDNgheNghiep";
			this.uxIDNgheNghiepDataGridViewColumn.HeaderText = "IDNgheNghiep";
			this.uxIDNgheNghiepDataGridViewColumn.Name = "uxIDNgheNghiepDataGridViewColumn";
			this.uxIDNgheNghiepDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDNgheNghiepDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDNgheNghiepDataGridViewColumn.ReadOnly = false;		
			//
			// uxTenDataGridViewColumn
			//
			this.uxTenDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTenDataGridViewColumn.DataPropertyName = "Ten";
			this.uxTenDataGridViewColumn.HeaderText = "Ten";
			this.uxTenDataGridViewColumn.Name = "uxTenDataGridViewColumn";
			this.uxTenDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTenDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTenDataGridViewColumn.ReadOnly = false;		
			//
			// uxMotaDataGridViewColumn
			//
			this.uxMotaDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxMotaDataGridViewColumn.DataPropertyName = "Mota";
			this.uxMotaDataGridViewColumn.HeaderText = "Mota";
			this.uxMotaDataGridViewColumn.Name = "uxMotaDataGridViewColumn";
			this.uxMotaDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxMotaDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxMotaDataGridViewColumn.ReadOnly = false;		
			//
			// uxMacDinhDataGridViewColumn
			//
			this.uxMacDinhDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxMacDinhDataGridViewColumn.DataPropertyName = "MacDinh";
			this.uxMacDinhDataGridViewColumn.HeaderText = "MacDinh";
			this.uxMacDinhDataGridViewColumn.Name = "uxMacDinhDataGridViewColumn";
			this.uxMacDinhDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxMacDinhDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxMacDinhDataGridViewColumn.ReadOnly = false;		
			//
			// uxTrangThaiDataGridViewColumn
			//
			this.uxTrangThaiDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxTrangThaiDataGridViewColumn.DataPropertyName = "TrangThai";
			this.uxTrangThaiDataGridViewColumn.HeaderText = "TrangThai";
			this.uxTrangThaiDataGridViewColumn.Name = "uxTrangThaiDataGridViewColumn";
			this.uxTrangThaiDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxTrangThaiDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxTrangThaiDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxNgheNghiepDataGridView);
			this.Name = "NgheNghiepDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxNgheNghiepBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				NgheNghiepDataGridViewEventArgs args = new NgheNghiepDataGridViewEventArgs();
				args.NgheNghiep = _currentNgheNghiep;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class NgheNghiepDataGridViewEventArgs : System.EventArgs
		{
			private Entities.NgheNghiep	_NgheNghiep;
	
			/// <summary>
			/// the  Entities.NgheNghiep instance.
			/// </summary>
			public Entities.NgheNghiep NgheNghiep
			{
				get { return _NgheNghiep; }
				set { _NgheNghiep = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxNgheNghiepDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnNgheNghiepDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxNgheNghiepDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnNgheNghiepDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxNgheNghiepDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDNgheNghiepDataGridViewColumn":
						e.Value = NgheNghiepList[e.RowIndex].IDNgheNghiep;
						break;
					case "uxTenDataGridViewColumn":
						e.Value = NgheNghiepList[e.RowIndex].Ten;
						break;
					case "uxMotaDataGridViewColumn":
						e.Value = NgheNghiepList[e.RowIndex].Mota;
						break;
					case "uxMacDinhDataGridViewColumn":
						e.Value = NgheNghiepList[e.RowIndex].MacDinh;
						break;
					case "uxTrangThaiDataGridViewColumn":
						e.Value = NgheNghiepList[e.RowIndex].TrangThai;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxNgheNghiepDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnNgheNghiepDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxNgheNghiepDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDNgheNghiepDataGridViewColumn":
						NgheNghiepList[e.RowIndex].IDNgheNghiep = (System.Guid)e.Value;
						break;
					case "uxTenDataGridViewColumn":
						NgheNghiepList[e.RowIndex].Ten = (System.String)e.Value;
						break;
					case "uxMotaDataGridViewColumn":
						NgheNghiepList[e.RowIndex].Mota = (System.String)e.Value;
						break;
					case "uxMacDinhDataGridViewColumn":
						NgheNghiepList[e.RowIndex].MacDinh = (System.Boolean)e.Value;
						break;
					case "uxTrangThaiDataGridViewColumn":
						NgheNghiepList[e.RowIndex].TrangThai = (System.Boolean)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
